<?php
$loader->requireOnce('includes/inPatientCore/InPatientCoreErrorCode.class.php');
$loader->requireOnce('includes/inPatientCore/InPatientCoreException.class.php');
$loader->requireOnce('includes/CoreErrorCode.class.php');
$loader->requireOnce('includes/CoreException.class.php');
$loader->requireOnce('includes/inPatientCore/InputServiceLoader.class.php');
$loader->requireOnce('ordo/InPatient.class.php');



/**
 * C_InSurgery Processor.
 * @package core.includes.inPatientCore
 * @author viethd
 * @version $Id$
 * @copyright 2009 LHV Company
 */
class C_ServiceInput extends Controller  {
	private $logger ;
	private $processor;


	/**
	 *
	 * @param $controller controller for build ui
	 */
	function __construct($template_mod = "general") {
		parent::Controller();
		$this->logger = LoggerManager::getLogger('core.controllers.C_ServiceInput');
		$this->template_mod = $template_mod;
		$this->view->path="service_input";
		$this->processor = new InputServiceLoader($this);
	}

	public function actionLoadServiceSelectionAjax($ticketId) {
		$result = array('error'=>array('code'=>0,'mess'=>''));
		$ticketId = $_GET['ticketId'];

		$this->logger->info('Start actionLoadServiceInputAjax');
		try {
			$result['result'] = $this->processor->loadServiceSelection($ticketId);
			
		} catch (InpatientCoreException $ex) {

			$result['error']['code'] = $ex->getErrorCode();
			$result['error']['mess'] = InPatientCoreErrorCode::getErrorMess($ex->getErrorCode());
			$this->logger->error('Load actionLoadServiceInputAjax fail. Error detail: '. $ex->getMessage());
		} catch (EnumException $ex) {
            $result['error']['code'] = $ex->getErrorCode();
            $result['error']['mess'] = CoreErrorCode::getErrorMess($ex->getErrorCode());
            $this->logger->error('Load actionLoadServiceInputAjax fail. Error detail: '. $ex->getMessage());
        }
		$this->logger->info('Finish actionLoadServiceInputAjax');
		return json_encode($result);
	}

	public function actionLoadServiceInputFormAjax() {
		$result = array('error'=>array('code'=>0,'mess'=>''), 'result'=>array());
		$ticketId = $_GET['ticketId'];
		$surgeryServiceCatergory = $_GET['surgeryServiceCatergory'];

		$this->logger->info('Start actionLoadServiceInputFormAjax');
		try {
			//$surgeryServiceType = Utils::getEnumKey(EnumerationConstant::SURGERY_CLASSIFY, $enumSurgeryServiceType);
			//$result['result']['surgeryServiceList'] = $this->processor->ListOfService($surgeryServiceType);
			$result['result']['inputForm'] = $this->processor->loadSurgeryServiceInputForm($ticketId, $surgeryServiceCatergory);			
	
		} catch (InpatientCoreException $ex) {
			$result['error']['code'] = $ex->getErrorCode();
			$result['error']['mess'] = InPatientCoreErrorCode::getErrorMess($ex->getErrorCode());
			$this->logger->error('Load actionLoadServiceInputFormAjax fail. Error detail: '. $ex->getMessage());
		} catch (EnumException $ex) {
            $result['error']['code'] = $ex->getErrorCode();
            $result['error']['mess'] = CoreErrorCode::getErrorMess($ex->getErrorCode());
            $this->logger->error('Load actionLoadServiceInputFormAjax fail. Error detail: '. $ex->getMessage());
        } 
		$this->logger->info('Finish actionLoadServiceInputFormAjax');
		return json_encode($result);

	}
	

}
?>